package com.fingard.dsp.web.page.c;

import java.util.HashMap;

import com.fingard.FGBiz;
import com.fingard.common.utils.json.JSONUtils;
import com.fingard.dsp.web.page.PageBase;

public class cipherData extends PageBase {
	@Override
	public void pageLoad() throws Exception{
		httpContext.response.isRtnBytes = false;
        httpContext.response.setContentType("txt", "");
        StringBuilder sbJson = new StringBuilder();
        String respCode = "";
        String respInfo = "";
		try {
			String reqJson = httpContext.request.httpReceiver.getReqBodyContent();
            HashMap<String, String> reqParams = JSONUtils.json2Map(reqJson);
            String cipherText = "";
            if (reqParams.containsKey("plainText") && reqParams.get("plainText").length() > 0) {
                String plainText = reqParams.get("plainText");
                cipherText = FGBiz.cipher.Encrypt(plainText);
            }
            sbJson.append("{");
            sbJson.append("\"respCode\":" + "\"0\",");
            sbJson.append("\"respInfo\":" + "\"\",");
            sbJson.append("\"result\":\"");
            sbJson.append(cipherText);
            sbJson.append("\"}");
            
		} catch (Exception ex) {
            FGBiz.limitMsg.exception(this.getClass().getSimpleName(), ex);
            respCode = "-1";
            respInfo = ex.toString();
        } finally {
        }
		if ("-1".equals(respCode)) {
            sbJson = new StringBuilder();
            sbJson.append("{");
            sbJson.append("\"respCode\":" + "\"" + respCode + "\",");
            sbJson.append("\"respInfo\":" + "\"" + respInfo + "\"");
            sbJson.append("}");
        }
        httpContext.response.respMsg = sbJson.toString();
	}
}
